package com.iflytek.jcy.supervise.clue.web;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.iflytek.jcy.supervise.clue.common.constants.AppConstants;
import com.iflytek.jcy.supervise.clue.common.enums.LoginSourceEnum;
import com.iflytek.jcy.supervise.clue.common.enums.ResultEnum;
import com.iflytek.jcy.supervise.clue.common.exception.BaseException;
import com.iflytek.jcy.supervise.clue.common.pojo.CommonResponse;
import com.iflytek.jcy.supervise.clue.common.util.ZzSecurityHelper;
import com.iflytek.jcy.supervise.clue.component.converter.BeanConverter;
import com.iflytek.jcy.supervise.clue.component.httpinterface.SjztHttpInterface;
import com.iflytek.jcy.supervise.clue.component.httpinterface.UapHttpInterface;
import com.iflytek.jcy.supervise.clue.component.httpinterface.param.ClueUser;
import com.iflytek.jcy.supervise.clue.component.httpinterface.param.LoginParamVO;
import com.iflytek.jcy.supervise.clue.component.httpinterface.result.OuterResponse;
import com.iflytek.jcy.supervise.clue.component.httpinterface.result.OuterUserInfo;
import com.iflytek.jcy.supervise.clue.component.httpinterface.result.OuterUserInfo2;
import com.iflytek.jcy.supervise.clue.component.httpinterface.uap.req.TokenDto;
import com.iflytek.jcy.supervise.clue.web.vo.UapMenu;
import com.iflytek.jcy.supervise.clue.web.vo.UapUserInfoVo;
import com.iflytek.jcy.supervise.clue.web.vo.UserInfoVO;
import com.iflytek.sec.uap.dto.ResponseDto;
import com.iflytek.sec.uap.dto.UserExtendDto;
import com.iflytek.sec.uap.dto.authority.AuthorityQueryDto;
import com.iflytek.sec.uap.dto.resource.ResourceDtoWithAuthority;
import com.iflytek.sec.uap.dto.role.BaseRole;
import com.iflytek.sec.uap.dto.user.BatchSaveUserDto;
import com.iflytek.sec.uap.dto.validate.ValidateUserDto;
import com.iflytek.sec.uap.model.UapAuthority;
import com.iflytek.sec.uap.model.UapOrg;
import com.iflytek.sec.uap.model.UapResource;
import com.iflytek.sec.uap.model.UapTokenModel;
import com.iflytek.sec.uap.model.UapUser;
import com.iflytek.sec.uap.model.UapUserOrgDetail;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.codec.Base64Encoder;

/**
 * <br>
 * 标题: 通用接口<br>
 * 描述: <br>
 * 公司: www.iflytek.com<br>
 *
 * @author dgyu
 * @time 2022年11月7日 下午12:08:28
 */
@RestController
@RequestMapping("/index")
@Api(tags = "通用接口")
public class IndexController {

    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Resource
    private ClueUser clueUser;
    @Resource
    private SjztHttpInterface sjztHttpInterface;
    @Resource
    private UapHttpInterface uapHttpInterface;
    @Resource
    private BeanConverter converter;
    @Resource
    private TokenDto tokenDto;
    public static final String CLIENT_SOURCE = "client";
    public static final String MANAGE_SOURCE = "manage";

    @GetMapping(value = "/getUserInfo/{uapUserId}")
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    public CommonResponse getUserInfo(@PathVariable(required = true) String uapUserId, HttpServletRequest request) {
        UapUserInfoVo uapUserInfoVo = new UapUserInfoVo();
        return getUserInfoByUap(uapUserId, request, uapUserInfoVo);
    }

    private CommonResponse getUserInfoByUap(String uapUserId, HttpServletRequest request, UapUserInfoVo uapUserInfoVo) {
        // 查询应用基本信息
        ResponseDto<JSONObject> responseDto = this.uapHttpInterface.getAppByCode(tokenDto.getAppCode(), tokenDto.getToken());
        // 无效票据处理 就先获取临时token
        if (ResultEnum.UAP_INVALID_TOKEN_ERROR.getDesc().equals(responseDto.getMessage())) {
            ResponseDto<UapTokenModel> tokenResp = uapHttpInterface.getToken(tokenDto);
            if (!tokenResp.isFlag() || tokenResp.getCode() != 0 || ObjectUtils.anyNull(tokenResp) || ObjectUtils.anyNull(tokenResp.getData())) {
                return CommonResponse.failed(ResultEnum.UAP_GET_TOKEN_ERROR);
            }
            tokenDto.setToken(tokenResp.getData().getToken());
            responseDto = this.uapHttpInterface.getAppByCode(tokenDto.getAppCode(), tokenDto.getToken());
        }
        if (!responseDto.isFlag() || responseDto.getCode() != 0 || ObjectUtils.anyNull(responseDto) || ObjectUtils.anyNull(responseDto.getData())) {
            return CommonResponse.failed(ResultEnum.UAP_QUERY_APP_BYCODE_ERROR);
        }
        JSONObject jSONObject = responseDto.getData();
        // 应用id
        String appId = jSONObject.getString("id");

        ResponseDto<UapUserOrgDetail> respUapUserOrgDetail = this.uapHttpInterface.getUserDetail(uapUserId, tokenDto.getToken());
        if (!respUapUserOrgDetail.isFlag() || respUapUserOrgDetail.getCode() != 0 || ObjectUtils.anyNull(respUapUserOrgDetail) || ObjectUtils.anyNull(respUapUserOrgDetail.getData())) {
            return CommonResponse.failed(ResultEnum.UAP_QUERY_USERINFO_BYUSERID_ERROR);
        }
        UapUserOrgDetail uapUserOrgDetail = respUapUserOrgDetail.getData();
        UserExtendDto userExtendDto = uapUserOrgDetail.getUserDetail();
        UapUser uapUser = userExtendDto.getUser();
        // 用户角色列表
        List<BaseRole> uapRoleList = userExtendDto.getRoles();
        // 角色id集合
        List<String> roleIdList = Optional.ofNullable(uapRoleList).map(Collection::stream).map(stream -> stream.map(BaseRole::getId).collect(Collectors.toList())).orElse(new ArrayList<>());
        // 获取功能权限集合
        List<UapAuthority> authorityList = null;
        if (CollectionUtils.isNotEmpty(roleIdList)) {
            AuthorityQueryDto authorityQueryDto = new AuthorityQueryDto();
            authorityQueryDto.setAppId(appId);
            authorityQueryDto.setPageNum(1);
            authorityQueryDto.setPageSize(1000);
            authorityQueryDto.setRoleIdList(roleIdList);
            ResponseDto<PageInfo<UapAuthority>> respUapAuthority = this.uapHttpInterface.getAuthorityList(authorityQueryDto, tokenDto.getToken());
            if (!respUapAuthority.isFlag() || respUapAuthority.getCode() != 0 || ObjectUtils.anyNull(respUapAuthority)) {
                return CommonResponse.failed(ResultEnum.UAP_MENU_ERROR);
            }
            PageInfo<UapAuthority> page = respUapAuthority.getData();
            authorityList = Optional.ofNullable(page).map(v -> v.getList()).orElse(new ArrayList<>());
            logger.info("userId:{}", uapUser.getId());
            logger.info("authorityList:{}", authorityList.toString());
        }
        if (CollectionUtils.isEmpty(authorityList)) {
            return CommonResponse.failed(ResultEnum.UAP_MENU_ERROR);
        }
        // UapServiceContext.getResourceService().getAllAuthResByAppIdUserId()
        // 根据appId和userId查询用户权限关联的资源列表
        ResponseDto<List<ResourceDtoWithAuthority>> respUapResource = this.uapHttpInterface.getAuthResByAppIdUserId(appId, uapUserId, tokenDto.getToken());
        if (!respUapResource.isFlag() || respUapResource.getCode() != 0 || ObjectUtils.anyNull(respUapResource)) {
            return CommonResponse.failed(ResultEnum.UAP_RESOURCE_NOT_ERROR);
        }
        List<ResourceDtoWithAuthority> resourceDtoWithAuthorityList = respUapResource.getData();
        List<List<UapResource>> resourceListList = Optional.ofNullable(resourceDtoWithAuthorityList).map(Collection::stream)
                .map(stream -> stream.filter(xx -> CollectionUtils.isNotEmpty(xx.getResourceList())).map(ResourceDtoWithAuthority::getResourceList).collect(Collectors.toList()))
                .orElse(new ArrayList<List<UapResource>>());

        List<UapResource> resourceList = resourceListList.stream().collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);
        authorityList.sort(Comparator.nullsLast(Comparator.comparing(UapAuthority::getSort, Comparator.nullsLast(Integer::compareTo))));
        // 将资源属性封装为树形菜单
        List<UapMenu> menus = resourceToMenu(authorityList);
        // 按照id升序
        if (CollectionUtils.isNotEmpty(menus)) {
            Collections.sort(menus);
        }
        menus = menus.get(0).getChilds();
        uapUserInfoVo = new UapUserInfoVo();
        BeanUtils.copyProperties(uapUser, uapUserInfoVo);
        UapOrg uapOrg = uapUserOrgDetail.getOrg();
        uapUserInfoVo.setId(uapUser.getId());
        uapUserInfoVo.setOrgCode(uapOrg.getCode());
        uapUserInfoVo.setOrgId(uapUser.getOrgId());
        uapUserInfoVo.setOrgName(uapUser.getOrgName());
        uapUserInfoVo.setOrgLevel(uapOrg.getLevel());

        uapUserInfoVo.setLoginName(uapUser.getLoginName());
        uapUserInfoVo.setName(uapUser.getName());
        uapUserInfoVo.setSfzh(uapUser.getIdNumber());
        uapUserInfoVo.setImage(uapUser.getProfile());
        uapUserInfoVo.setAuthorityList(menus);
        uapUserInfoVo.setRoleList(uapRoleList);
        uapUserInfoVo.setPhone(uapUser.getPhone());
        uapUserInfoVo.setResourceList(resourceList);
        return CommonResponse.success(uapUserInfoVo);
    }

    /**
     * 两层循环实现建树 将资源属性封装为树形菜单
     *
     * @param treeNodes 传入的树节点列表
     * @return
     */
    private List<UapMenu> resourceToMenu(List<UapAuthority> treeNodes) {
        // 最终格式
        List<UapMenu> trees = new ArrayList<UapMenu>();
        for (UapAuthority resourceAuth : treeNodes) {
            if (null != resourceAuth) {
                UapMenu leftMenu = convertMenu(resourceAuth);
                if ("0".equals(resourceAuth.getParentId())) {
                    trees.add(findChildren(leftMenu, treeNodes));
                }
            }
        }
        return trees;
    }

    /**
     * 递归查找子节点
     *
     * @param treeNodes
     * @return
     */
    private UapMenu findChildren(UapMenu leftMenu, List<UapAuthority> treeNodes) {
        // 将资源属性封装为树形菜单
        for (UapAuthority it : treeNodes) {
            if (null != it && null != it.getParentId() && null != leftMenu && it.getParentId().equals(leftMenu.getId())) {
                if (leftMenu.getChilds() == null) {
                    leftMenu.setChilds(new ArrayList<UapMenu>());
                }
                leftMenu.getChilds().add(findChildren(convertMenu(it), treeNodes));
            }
        }
        // 按照id升序
        if (null != leftMenu.getChilds()) {
            Collections.sort(leftMenu.getChilds());
        }
        return leftMenu;
    }

    /**
     * <br>
     * 适用场景:将资源属性转化为菜单属性 <br>
     * 调用方式: <br>
     * 业务逻辑说明<br>
     *
     * @param resource
     * @return
     * @autho dgyu
     * @time 2022年12月12日 下午8:52:46
     */
    private UapMenu convertMenu(UapAuthority resource) {
        UapMenu menu = new UapMenu();
        BeanUtils.copyProperties(resource, menu);
        return menu;
    }

    @GetMapping("/user")
    @ApiOperation(value = "获取用户信息并登录", notes = "仅限于从赛威讯2.0跳到线索管理系统的场景")
    public CommonResponse getUserInfo(@RequestParam String dwbm, @RequestParam String rybm, HttpServletRequest request) {
        logger.info("获取用户信息并登录, dwbm: {}, rybm: {}", dwbm, rybm);
        // 根据登录名查询用户信息
        ResponseDto<BatchSaveUserDto> responseUserDetail = this.uapHttpInterface.getUserDetailByLoginName(rybm, this.tokenDto.getToken());
        // 无效票据处理 就先获取临时token
        if (ResultEnum.UAP_INVALID_TOKEN_ERROR.getDesc().equals(responseUserDetail.getMessage())) {
            ResponseDto<UapTokenModel> tokenResp = uapHttpInterface.getToken(tokenDto);
            if (!tokenResp.isFlag() || tokenResp.getCode() != 0 || ObjectUtils.anyNull(tokenResp) || ObjectUtils.anyNull(tokenResp.getData())) {
                return CommonResponse.failed(ResultEnum.UAP_GET_TOKEN_ERROR);
            }
            tokenDto.setToken(tokenResp.getData().getToken());
            responseUserDetail = this.uapHttpInterface.getUserDetailByLoginName(rybm, tokenDto.getToken());
        }
        if (!responseUserDetail.isFlag() || responseUserDetail.getCode() != 0 || ObjectUtils.anyNull(responseUserDetail) || ObjectUtils.anyNull(responseUserDetail.getData())) {
            return CommonResponse.failed(ResultEnum.UAP_QUERY_USERINFO_BYUSERID_ERROR);
        }
        JSONObject js = new JSONObject();
        js.put("rybm", rybm);
        js.put("dwbm", dwbm);
        OuterResponse<OuterUserInfo2> response = sjztHttpInterface.userInfo(js);
        if (response == null || response.getData() == null) {
            return CommonResponse.failed("获取用户信息失败");
        }
        OuterUserInfo2 outerUserInfo2 = response.getData();
        OuterUserInfo userInfo = converter.convert(outerUserInfo2);

        // userInfoService.saveOrUpdate(userInfo, null);
        UserInfoVO data = converter.fromOuter(userInfo.getUserInfo());
        List<OuterUserInfo.Role> roles = userInfo.getRoles();
        if (CollectionUtils.isNotEmpty(roles)) {
            data.setBmbm(roles.get(0).getBmbm());
            data.setJsmc(roles.get(0).getJsmc());
        }
        data.setIsAdmin(false);
        data.setSaToken(StpUtil.getTokenInfo().getTokenValue());

        BatchSaveUserDto batchSaveUserDto = responseUserDetail.getData();
        UapUser uapUser = Optional.ofNullable(batchSaveUserDto).map(BatchSaveUserDto::getUser).orElse(new UapUser());
        CommonResponse commonResponse = getUserInfo(uapUser.getId(), request);
        UapUserInfoVo uapUserInfoVo = null;
        if (commonResponse.isSuccess()) {
            Object o = Optional.ofNullable(commonResponse).map(CommonResponse::getData).orElse(new Object());
            uapUserInfoVo = (UapUserInfoVo) o;
            data.setUapUserInfoVo(uapUserInfoVo);
        }
        // 创建用户session
        StpUtil.login(uapUser.getId(), MANAGE_SOURCE);
        StpUtil.getSession().set("user", userInfo);
        StpUtil.getSession().set("isAdmin", false);
        StpUtil.getSession().set(AppConstants.LOGIN_USER_KEY, uapUserInfoVo);
        // StpUtil.getSession().set(AppConstants.LOGIN_USER_KEY, Arrays.asList("/task/addTask","/task/queryTaskManageList"));

        logger.info("获取用户信息并登录结束");
        return CommonResponse.success(data);

    }

    @PostMapping("/loginout")
    @ApiOperation(value = "登出")
    public CommonResponse loginout(HttpServletRequest request) {
        StpUtil.getSession().clear();
        StpUtil.logout();
        return CommonResponse.success("退出成功");
    }

    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public CommonResponse login(HttpServletRequest request, @Validated @RequestBody LoginParamVO outerLoginParam) throws Exception {
        // AES解密
        String password = ZzSecurityHelper.decryptAES(outerLoginParam.getPassword());
        outerLoginParam.setPassword(password);
        logger.info("线索管理平台登录, username: {},souce:{}", outerLoginParam.getUsername(), outerLoginParam.getSource());
        LoginSourceEnum loginSourceEnum = LoginSourceEnum.getSource(outerLoginParam.getSource());
        UserInfoVO data = new UserInfoVO();
        logger.info("哈哈哈哈  这里是测试JRbel插件bbbbb");
        switch (loginSourceEnum) {
            case CLUE_PLATFORM:
                return this.clueLogin(outerLoginParam, data, request);
            case TYYW_PLATFORM:
                return this.tyywLogin(outerLoginParam, request);
            default:
                return CommonResponse.failed("登录方式错误，clue:线索管理平台 tyyw:统一业务2.0");
        }
    }

    private CommonResponse clueLogin(LoginParamVO outerLoginParam, UserInfoVO data, HttpServletRequest request) {
        String username = outerLoginParam.getUsername();
        String password = outerLoginParam.getPassword();
        UapUser uapUser = validateUser(username, password);
        data.setDlbm(uapUser.getLoginName());
        data.setRybm(uapUser.getId());
        data.setMc(uapUser.getName());
        data.setDwmc(uapUser.getOrgName());
        data.setBmbm(uapUser.getOrgCode());
        CommonResponse commonResponse = getUserInfo(uapUser.getId(), request);
        UapUserInfoVo uapUserInfoVo = null;
        if (commonResponse.isSuccess()) {
            Object o = Optional.ofNullable(commonResponse).map(CommonResponse::getData).orElse(new Object());
            uapUserInfoVo = (UapUserInfoVo) o;
            data.setUapUserInfoVo(uapUserInfoVo);
        }
        StpUtil.login(uapUser.getId(), "");
        StpUtil.getSession().set("user", uapUser);
        StpUtil.getSession().set("isAdmin", true);
        // StpUtil.getSession().set(AppConstants.LOGIN_USER_KEY, Arrays.asList("/task/addTask","/task/queryTaskManageList"));
        data.setIsAdmin(true);
        data.setSaToken(StpUtil.getTokenValue());
        StpUtil.getSession().set(AppConstants.LOGIN_USER_KEY, uapUserInfoVo);
        return CommonResponse.success(data);
    }

    private UapUser validateUser(String username, String password) {
        String base64Passsword = new Base64Encoder().encode(password.getBytes());
        ValidateUserDto validateUserDto = new ValidateUserDto();
        validateUserDto.setLoginName(username);
        validateUserDto.setPassword(base64Passsword);
        ResponseDto<UapUser> responseDto = uapHttpInterface.validateUser(validateUserDto, tokenDto.getToken());
        // 无效票据处理 就先获取临时token
        if (ResultEnum.UAP_INVALID_TOKEN_ERROR.getDesc().equals(responseDto.getMessage())) {
            ResponseDto<UapTokenModel> tokenResp = uapHttpInterface.getToken(tokenDto);
            if (!tokenResp.isFlag() || tokenResp.getCode() != 0 || ObjectUtils.anyNull(tokenResp) || ObjectUtils.anyNull(tokenResp.getData())) {
                throw new BaseException(ResultEnum.UAP_GET_TOKEN_ERROR);
            }
            tokenDto.setToken(tokenResp.getData().getToken());
            // 重新校验一次用户
            responseDto = uapHttpInterface.validateUser(validateUserDto, tokenDto.getToken());
        }
        if (!responseDto.isFlag() || responseDto.getCode() != 0 || ObjectUtils.anyNull(responseDto) || ObjectUtils.anyNull(responseDto.getData())) {
            throw new BaseException(ResultEnum.USERNAME_PASSWORD_ERROR);
        }
        return responseDto.getData();
    }

    private CommonResponse tyywLogin(LoginParamVO outerLoginParam, HttpServletRequest request) {
        logger.info("统一业务2.0登录, username: {}", outerLoginParam.getUsername());
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("dlbm", outerLoginParam.getUsername());
        jSONObject.put("kl", outerLoginParam.getPassword());
        jSONObject.put("dwbm", outerLoginParam.getDwbm());
        // 调用中台
        OuterResponse<OuterUserInfo> outerResponse = sjztHttpInterface.login(jSONObject);
        if (outerResponse == null) {
            return CommonResponse.failed(ResultEnum.LOGIN_FAILED);
        }
        if (!outerResponse.getSuccess()) {
            throw new BaseException(ResultEnum.LOGIN_FAILED, StringUtils.isEmpty(outerResponse.getMessage()) ? outerResponse.getMsg() : outerResponse.getMessage());
        }
        OuterUserInfo userInfo = outerResponse.getData();

        // 校验uap并获取Uap用户信息
        UserInfoVO data = converter.fromOuter(userInfo.getUserInfo());

        // 使用人员编码 作为登录名验证用户
        /*UapUser validateUser = this.validateUser(userInfo.getUserInfo().getRybm(), outerLoginParam.getPassword());*/
        //由于同步人员信息密码是uap默认密码123456 这里不能用密码去校验 而是使用人员编码作为登录名去校验

        // 根据登录名查询用户信息
        ResponseDto<BatchSaveUserDto> responseUserDetail = this.uapHttpInterface.getUserDetailByLoginName(userInfo.getUserInfo().getRybm(), this.tokenDto.getToken());
        // 无效票据处理 就先获取临时token
        if (ResultEnum.UAP_INVALID_TOKEN_ERROR.getDesc().equals(responseUserDetail.getMessage())) {
            ResponseDto<UapTokenModel> tokenResp = uapHttpInterface.getToken(tokenDto);
            if (!tokenResp.isFlag() || tokenResp.getCode() != 0 || ObjectUtils.anyNull(tokenResp) || ObjectUtils.anyNull(tokenResp.getData())) {
                return CommonResponse.failed(ResultEnum.UAP_GET_TOKEN_ERROR);
            }
            tokenDto.setToken(tokenResp.getData().getToken());
            responseUserDetail = this.uapHttpInterface.getUserDetailByLoginName(userInfo.getUserInfo().getRybm(), tokenDto.getToken());
        }
        if (!responseUserDetail.isFlag() || responseUserDetail.getCode() != 0 || ObjectUtils.anyNull(responseUserDetail) || ObjectUtils.anyNull(responseUserDetail.getData())) {
            return CommonResponse.failed(ResultEnum.UAP_QUERY_USERINFO_BYUSERID_ERROR);
        }
        BatchSaveUserDto batchSaveUserDto = responseUserDetail.getData();

        CommonResponse commonResponse = getUserInfo(batchSaveUserDto.getUser().getId(), request);
        UapUserInfoVo uapUserInfoVo = null;
        if (commonResponse.isSuccess()) {
            Object o = Optional.ofNullable(commonResponse).map(CommonResponse::getData).orElse(new Object());
            uapUserInfoVo = (UapUserInfoVo) o;
            data.setUapUserInfoVo(uapUserInfoVo);
        } else {
            return commonResponse;
        }
        // 创建用户session
        StpUtil.login(uapUserInfoVo.getId(), MANAGE_SOURCE);
        StpUtil.getSession().set("user", userInfo);
        StpUtil.getSession().set("isAdmin", false);
        StpUtil.getSession().set(AppConstants.LOGIN_USER_KEY, uapUserInfoVo);

        List<OuterUserInfo.Role> roles = userInfo.getRoles();
        data.setBmbm(roles.get(0).getBmbm());
        data.setJsmc(roles.get(0).getJsmc());
        data.setIsAdmin(false);
        data.setSaToken(StpUtil.getTokenInfo().getTokenValue());
        data.setDlbm(outerLoginParam.getUsername());
        logger.info("用户登录结束");
        return CommonResponse.success(data);
    }
}